package com.arron.algorithm.leetcodetop100.双指针;

/**
 * . 盛最多水的容器
 */
public class 盛最多水的容器 {

    public static void main(String[] args) {

        int arr[] = {1,1};
        System.out.println(maxArea1(arr));

    }

    //暴力解法，O（n2）
    public static int maxArea1(int[] height) {

        if (height.length<2){
            return 0;
        }
        int maxArea = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = height.length-1;j>i;j--) {
                int h = Math.min(height[i], height[j]);
                int tempArea = (j - i) * h;
                maxArea = Math.max(tempArea, maxArea);
            }

        }


        return maxArea;

    }
    //优化时间复杂度，明天来写
    public static int maxArea2(int[] height) {

        if (height.length<2){
            return 0;
        }
        int maxArea = 0;
        int l = 0;
        int r =height.length-1;
      while (l<r){
          maxArea = Math.max((r-l)*Math.min(height[l],height[r]),maxArea);
          if (height[l] > height[r]){
              r--;

          }else {
              l++;
          }
      }
        return maxArea;

    }


    // w*h = s
}
